/// 某个医院的租金明细列表

var app = getApp()
//常量数据配置
var ConstantData = require('../../../../common/constant_data.js')
//获取应用实例  
Page({
  
  data: {
    
    leseDetail:'',
    hospitalName:'',
    pageSize:20,
    pageNum:1,
    orderList:[],
    loading:true,
    loadingComplete:false
  },


  
  onLoad: function (options) {

    var that = this;
    console.log("--------options->", options);
    var mecId = options.mecId;
    var hospitalName = options.hospitalName;
    var date = options.date;
    var dateStr = date.substr(0, 4) + "-" + date.substr(4, 2) + "-" + date.substr(6, 2);
    var position = options.position;
    var startDate = dateStr + " 00:00:00";
    var endDate = dateStr + " 23:59:59";
    this.setData({
      mecId: mecId,
      hospitalName: hospitalName,
      startDate: startDate,
      endDate: endDate,
      position: position
    });

    that.init(startDate, endDate, position);    
  },
 
 
  
  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function () {
   
    var that = this;
    if (that.data.loading && !that.data.loadingComplete) {
      that.setData({
        loading:false,
        pageNum: that.data.pageNum + 1,  //每次触发上拉事件，把searchPageNum+1  
      });
      that.init(that.data.startDate,that.data.endDate,that.data.position);
    }
  },
  

  init: function (startDate, endDate, position) {
    console.log("----------pageNum=",this.data.pageNum)
    console.log(">>>>>>>>>mecId",this.data.mecId);
    var that = this;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_statistic/lease/position_detail',
        header: header,
        data: {
          startDate: startDate,
          endDate: endDate,
          mecId: that.data.mecId,
          position: position,
          startNum: (that.data.pageNum-1)* that.data.pageSize,
          pageSize: that.data.pageSize
        },
        success: function (res) {
          console.log("cccc---->", res);
          if(res.data.length == 0) {
            that.setData({
              loadingComplete:true
            });
            return;
          }
          var list = that.data.orderList;
          for(var i=0;i<res.data.length;i++) {
            if (res.data[i].uur_return_time) {
            }else {
              res.data[i].uur_return_time = "未归还"
            }
            res.data[i].uur_order_code = res.data[i].uur_order_code.substr(8);
            list.push(res.data[i])
          }
          that.setData({
            orderList: list,
            loading:true
          })
        }
      })
    });  

   
  }

})  


